package com.cindata

import com.cindata.dic.DictoryTypeDict
import com.cindata.dictionary.*
import com.cindata.dimension.*

class BootStrap
{
    def init =
        {
            // 机构级别
            if (AccountLevelDict.count() < 1)
            {
                new AccountLevelDict([name: '总行', code: '0']).save()
                new AccountLevelDict([name: '一级分行（或直属分行）', code: '1']).save()
                new AccountLevelDict([name: '二级分行（地级市）', code: '2']).save()
                new AccountLevelDict([name: '一级支行（区或县级支行）', code: '3']).save()
                new AccountLevelDict([name: '银行分理处/储蓄网点', code: '4']).save()
            }

            // 添加总行机构
            if (Account.count() < 1)
            {
                println 'init account data'

                def account = new Account()
                account.name = '中国银行总行'
                account.phone = '95566'
                account.cellphone = '010-66596688'
                account.contact = '陈四清'
                account.address = '北京市西城区复兴门内大街1号'
                account.city = City.findByNameAndAreaLevel('北京市', 2)
                account.level = AccountLevelDict.findByName("总行")
                account.x = 116.379295
                account.y = 39.914244
                account.save()
            }

            if (Role.count() < 1)
            {
                println 'init role data'

                def r = new Role()
                r.authority = 'ROLE_ADMINISTRATOR'
                r.name = '全系统管理'
                r.save()
            }

            if (!Role.findByAuthority('ROLE_GD_LOGO'))
            {
                def r = new Role()
                r.authority = 'ROLE_GD_LOGO'
                r.name = '广东正诚'
                r.save()
            }

            if (!Role.findByAuthority('ROLE_TAX'))
            {
                def r = new Role()
                r.authority = 'ROLE_TAX'
                r.name = '地税系统管理'
                r.save()
            }

            if (!Role.findByAuthority('ROLE_PUBLIC_FUND'))
            {
                def r = new Role()
                r.authority = 'ROLE_PUBLIC_FUND'
                r.name = '公积金系统管理'
                r.save()
            }

            if (!Role.findByAuthority('ROLE_PUBLIC_FUND_YS'))
            {
                def r = new Role()
                r.authority = 'ROLE_PUBLIC_FUND_YS'
                r.name = '公积金演示'
                r.save()
            }

            if (!Role.findByAuthority('ROLE_CUSTOMER_MANAGER'))
            {
                def r = new Role()
                r.authority = 'ROLE_CUSTOMER_MANAGER'
                r.name = '客户经理'
                r.save()

                r = new Role()
                r.authority = 'ROLE_CUSTOMER_MANAGER_LEADER'
                r.name = '客户经理主管'
                r.save()

                r = new Role()
                r.authority = 'ROLE_DEPARTMENT_MANAGER'
                r.name = '部门经理'
                r.save()
            }

            if (User.count() < 1)
            {
                println 'init contact data'

                def c = new User()
                c.username = 'admin'
                c.password = '123456'
                c.fullName = "管理员"
                // c.cellphone = "18513603065"
                c.account = Account.first()
                c.save()

                UserRole.create(c, Role.findByAuthority('ROLE_ADMINISTRATOR'))
            }

            if (!User.findByUsername('gdadmin'))
            {
                def gdc = new User()
                gdc.username = 'gdadmin'
                gdc.password = '123456'
                gdc.fullName = "广东管理员"
                // c.cellphone = "18513603065"
                gdc.account = Account.first()
                gdc.save()
                UserRole.create(gdc, Role.findByAuthority('ROLE_ADMINISTRATOR'))
                UserRole.create(gdc, Role.findByAuthority('ROLE_GD_LOGO'))
            }

            //menu 初始化
            if (Menu.count() < 1)
            {
                Menu.initData()
            }

            //RoleMenu 初始化
            if (RoleMenu.count() < 1)
            {
                def role

                role = Role.findByAuthority('ROLE_ADMINISTRATOR')
                Menu.list().each {
                    new RoleMenu([role: role, menu: it]).save()
                }


                // new RoleMenu([role: role, menu: Menu.findByTitle('首页')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('评估')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('评估查询')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('崂山')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('市内三区')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('评估管理')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('数据管理')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('统计分析')]).save()
                //            new RoleMenu([role: role, menu: Menu.findByTitle('系统管理')]).save()
                //            new RoleMenu([role: role, menu: Menu.findByTitle('用户')]).save()
                //            new RoleMenu([role: role, menu: Menu.findByTitle('登录明细')]).save()

                // role = Role.findByAuthority('ROLE_PUBLIC_FUND')
                // new RoleMenu([role: role, menu: Menu.findByTitle('首页')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('押品')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('导入')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('分析')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('地图')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('热力图')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('聚合图')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('散点图')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('系统管理')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('用户')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('登录明细')]).save()

                // role = Role.findByAuthority('ROLE_PUBLIC_FUND_YS')
                // new RoleMenu([role: role, menu: Menu.findByTitle('首页')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('押品')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('导入')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('分析')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('地图')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('热力图')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('聚合图')]).save()
                // new RoleMenu([role: role, menu: Menu.findByTitle('散点图')]).save()

            }

            if (EstateStatusDict.count() < 1)
            {
                new EstateStatusDict([name: '在押', code: '1']).save()
                new EstateStatusDict([name: '解押', code: '2']).save()
            }
            else
            {
                if (!EstateStatusDict.findByName('处置'))
                {
                    new EstateStatusDict([name: '处置', code: '3']).save()
                }
                if (!EstateStatusDict.findByName('清退'))
                {
                    new EstateStatusDict([name: '清退', code: '4']).save()
                }
            }
            if (EvaluateDict.count() < 1)
            {
                new EvaluateDict([name: '自动评估', code: '1']).save()
                new EvaluateDict([name: '人工评估', code: '2']).save()
            }
            else
            {
                if (!EvaluateDict.findByName("自动和人工评估"))
                {
                    new EvaluateDict([name: '自动和人工评估', code: '3']).save()
                }
                if (!EvaluateDict.findByName("评估机构"))
                {
                    new EvaluateDict([name: '评估机构', code: '4']).save()
                }
            }
            if (ExecStatusDict.count() < 1)
            {
                new ExecStatusDict([name: '成功', code: '1']).save()
                new ExecStatusDict([name: '执行中', code: '2']).save()
                new ExecStatusDict([name: '失败', code: '-1']).save()
                new ExecStatusDict([name: '部分失败', code: '-2']).save()
            }
            else
            {
                if (!ExecStatusDict.findByName("未执行"))
                {
                    new ExecStatusDict([name: '未执行', code: '0']).save()
                }
            }
            if (ImportTypeDict.count() < 1)
            {
                new ImportTypeDict([name: '新增', code: 'I']).save()
                new ImportTypeDict([name: '更新', code: 'U']).save()
            }
            if (ImportFileTypeDict.count() < 1)
            {
                new ImportFileTypeDict([name: '押品', code: 'Estate']).save()
                new ImportFileTypeDict([name: '还款', code: 'Repayment']).save()
            }
            if (AccountNatureDict.count() < 1)
            {
                new AccountNatureDict([name: '本地', code: 'Local']).save()
                new AccountNatureDict([name: '异地', code: 'Remote']).save()
                new AccountNatureDict([name: '其他', code: 'Other']).save()
            }
            if (DepositedStateDict.count() < 1)
            {
                new DepositedStateDict([name: '默认', code: 'Other']).save()
                new DepositedStateDict([name: '正常缴存', code: 'NormalPay']).save()
                new DepositedStateDict([name: '封存', code: 'SafeKeeping']).save()
            }
            if (ForwardLoanStepDict.count() < 1)
            {
                new ForwardLoanStepDict([name: '抵押回执环节', code: 'MortgageReceiptStep']).save()
                new ForwardLoanStepDict([name: '房产证完税环节', code: 'CertificatePayTaxesStep']).save()
                new ForwardLoanStepDict([name: '房产证（新证）环节', code: 'CertificateNewStep']).save()
                new ForwardLoanStepDict([name: '其他', code: 'Other']).save()
            }
            if (GuaranteeMethodDict.count() < 1)
            {
                new GuaranteeMethodDict([name: '全程担保', code: 'WholeJourney']).save()
                new GuaranteeMethodDict([name: '阶段担保', code: 'Stage']).save()
            }
            if (HouseTypeDict.count() < 1)
            {
                new HouseTypeDict([name: '一手期房', code: 'FIRSTFORWARD']).save()
                new HouseTypeDict([name: '一手现房', code: 'FIRST']).save()
                new HouseTypeDict([name: '二手现房', code: 'SECOND']).save()
            }
            if (LoanMethodDict.count() < 1)
            {
                new LoanMethodDict([name: '抵押放款', code: 'SecuredLoan']).save()
                new LoanMethodDict([name: '提前放款', code: 'ForwardLoan']).save()
            }
            if (OrganizationNatureDict.count() < 1)
            {
                new OrganizationNatureDict([name: '国有企业', code: 'StateOwnedEnterprise']).save()
                new OrganizationNatureDict([name: '国有控股企业', code: 'StateHoldingEnterprise']).save()
                new OrganizationNatureDict([name: '外资企业', code: 'ForeignOwnedEnterprise']).save()
                new OrganizationNatureDict([name: '合资企业', code: 'JointVentureEnterprise']).save()
                new OrganizationNatureDict([name: '私营企业', code: 'PrivateEnterprise']).save()
                new OrganizationNatureDict([name: '事业单位', code: 'PublicInstitution']).save()
                new OrganizationNatureDict([name: '国家行政机关', code: 'GovermmentInstitution']).save()
            }
            else
            {
                if (!OrganizationNatureDict.findByName("中外合资经营企业"))
                {
                    new OrganizationNatureDict([name: '中外合资经营企业', code: '1']).save()
                    new OrganizationNatureDict([name: '外商投资企业', code: '2']).save()
                    new OrganizationNatureDict([name: '合资经营企业（港或澳台资）', code: '3']).save()
                    new OrganizationNatureDict([name: '港澳台投资企业', code: '4']).save()
                    new OrganizationNatureDict([name: '集体企业', code: '5']).save()
                    new OrganizationNatureDict([name: '外商投资股份有限公司', code: '6']).save()
                    new OrganizationNatureDict([name: '内资企业', code: '7']).save()
                    new OrganizationNatureDict([name: '股份合作企业', code: '8']).save()
                    new OrganizationNatureDict([name: '合作经营企业（港或澳台资）', code: '9']).save()
                    new OrganizationNatureDict([name: '股份有限公司', code: '10']).save()
                    new OrganizationNatureDict([name: '有限责任公司', code: '11']).save()
                    new OrganizationNatureDict([name: '联营企业', code: '12']).save()
                    new OrganizationNatureDict([name: '港澳台商投资购房有限公司', code: '13']).save()
                    new OrganizationNatureDict([name: '港澳台独资经营企业', code: '14']).save()
                }
            }
            if (RepaymentStateDict.count() < 1)
            {
                new RepaymentStateDict([name: '正常还款', code: 'Normal']).save()
                new RepaymentStateDict([name: '逾期还款', code: 'Overdue']).save()
                new RepaymentStateDict([name: '已还清', code: 'Payoff']).save()
                new RepaymentStateDict([name: '提前还款', code: 'Advance']).save()
            }

            if (OverdueStateDict.count() < 1)
            {
                new OverdueStateDict([name: '已还', code: 'HasPay']).save()
                new OverdueStateDict([name: '未还', code: 'NoPay']).save()
            }
            if (PrepaymentTypeDict.count() < 1)
            {
                new PrepaymentTypeDict([name: '全部提前', code: 'ALL']).save()
                new PrepaymentTypeDict([name: '部分提前', code: 'PART']).save()
            }
            if (RepaymentModeDict.count() < 1)
            {
                new RepaymentModeDict([name: '等额本金', code: 'AverageCapital']).save()
                new RepaymentModeDict([name: '等额本息', code: 'AverageCapitalPlusInterest']).save()
            }
            if (RepaymentTypeDict.count() < 1)
            {
                new RepaymentTypeDict([name: '正常还款', code: 'Normal']).save()
                new RepaymentTypeDict([name: '提前还款', code: 'InAdvance']).save()
                new RepaymentTypeDict([name: '逾期还款', code: 'Overdue']).save()
                new RepaymentTypeDict([name: '转逾期', code: 'TurnOver']).save()
            }
            if (LTVDimension.count() < 1)
            {
                new LTVDimension([label: '0%-20%', minValue: '0', maxValue: '20', orderNumber: 1]).save()
                new LTVDimension([label: '20%-40%', minValue: '20', maxValue: '40', orderNumber: 2]).save()
                new LTVDimension([label: '40%-60%', minValue: '40', maxValue: '60', orderNumber: 3]).save()
                new LTVDimension([label: '60%-80%', minValue: '60', maxValue: '80', orderNumber: 4]).save()
                new LTVDimension([label: '80%-100%', minValue: '80', maxValue: '100', orderNumber: 5]).save()
                new LTVDimension([label: '100%以上', minValue: '100', maxValue: '1000', orderNumber: 6]).save()
            }
            if (YearLimitDimension.count() < 1)
            {
                new YearLimitDimension([label: '1-6月', minValue: '0', maxValue: '6', orderNumber: 1]).save()
                new YearLimitDimension([label: '6-12月', minValue: '6', maxValue: '12', orderNumber: 2]).save()
                new YearLimitDimension([label: '1-3年', minValue: '12', maxValue: '36', orderNumber: 3]).save()
                new YearLimitDimension([label: '3-5年', minValue: '36', maxValue: '60', orderNumber: 4]).save()
                new YearLimitDimension([label: '5-10年', minValue: '60', maxValue: '120', orderNumber: 5]).save()
                new YearLimitDimension([label: '10-20年', minValue: '120', maxValue: '240', orderNumber: 6]).save()
                new YearLimitDimension([label: '20-30年', minValue: '240', maxValue: '360', orderNumber: 7]).save()
                new YearLimitDimension([label: '30年以上', minValue: '360', maxValue: '1000000', orderNumber: 8]).save()
            }
            if (AmountDimension.count() < 1)
            {
                new AmountDimension([label: '50万以下', minValue: '0', maxValue: '50000', orderNumber: 1]).save()
                new AmountDimension([label: '50万-100万', minValue: '50000', maxValue: '1000000', orderNumber: 2]).save()
                new AmountDimension([label: '100万-200万', minValue: '1000000', maxValue: '2000000', orderNumber: 3]).save()
                new AmountDimension([label: '200万-500万', minValue: '2000000', maxValue: '5000000', orderNumber: 4]).save()
                new AmountDimension([label: '500万以上', minValue: '5000000', maxValue: '1000000000', orderNumber: 5]).save()
            }
            if (RiskDimension.count() < 1)
            {
                new RiskDimension([label: '低风险', minValue: '0', maxValue: '60', orderNumber: 1]).save()
                new RiskDimension([label: '中风险', minValue: '60', maxValue: '80', orderNumber: 2]).save()
                new RiskDimension([label: '高风险', minValue: '80', maxValue: '100', orderNumber: 3]).save()
                new RiskDimension([label: '损失', minValue: '100', maxValue: '1000000', orderNumber: 4]).save()
            }
            if (ValuationHistoryDimension.count() < 1)
            {
                new ValuationHistoryDimension([label: '房屋编号', minValue: '0', maxValue: '60', orderNumber: 1]).save()
                new ValuationHistoryDimension([label: '地址', minValue: '0', maxValue: '2000', orderNumber: 2]).save()
            }
            if (DepositBaseDimension.count() < 1)
            {
                new DepositBaseDimension([label: '<=7000', minValue: '0', maxValue: '7000', orderNumber: 1]).save()
                new DepositBaseDimension([label: '7000-10000', minValue: '7000', maxValue: '10000', orderNumber: 2]).save()
                new DepositBaseDimension([label: '10000-15000', minValue: '10000', maxValue: '15000', orderNumber: 3]).save()
                new DepositBaseDimension([label: '>15000', minValue: '15000', maxValue: '1000000', orderNumber: 4]).save()
            }

            if (ValueRateDimension.count() < 1)
            {
                new ValueRateDimension([label: '-30%以下', minValue: '-10000', maxValue: '-30', orderNumber: 1]).save()
                new ValueRateDimension([label: '-30%到0', minValue: '-29', maxValue: '0', orderNumber: 2]).save()
                new ValueRateDimension([label: '0到30%', minValue: '1', maxValue: '29', orderNumber: 3]).save()
                new ValueRateDimension([label: '30%以上', minValue: '30', maxValue: '10000', orderNumber: 4]).save()
            }
            if (AgeDimension.count() < 1)
            {
                new AgeDimension([label: '25岁及以下', minValue: '0', maxValue: '300', orderNumber: 1]).save()
                new AgeDimension([label: '26-35岁', minValue: '300', maxValue: '420', orderNumber: 2]).save()
                new AgeDimension([label: '36-45岁', minValue: '420', maxValue: '540', orderNumber: 3]).save()
                new AgeDimension([label: '46-55岁', minValue: '540', maxValue: '660', orderNumber: 4]).save()
                new AgeDimension([label: '56岁及以上', minValue: '660', maxValue: '10000', orderNumber: 5]).save()
            }
            if (BuildAreaDimension.count() < 1)
            {
                new BuildAreaDimension([label: '0-90', minValue: '0', maxValue: '90', orderNumber: 1]).save()
                new BuildAreaDimension([label: '90-144', minValue: '90', maxValue: '144', orderNumber: 2]).save()
                new BuildAreaDimension([label: '144以上', minValue: '144', maxValue: '100000000', orderNumber: 3]).save()
            }
            //BuildingTypeDict 初始化
            BuildingTypeDict.initData()

            if (Fees.count() < 1)
            {
                new Fees([name: '押品估值', code: 'EstateEvaluate']).save()
                new Fees([name: '小区评分', code: 'DistrictScore']).save()
            }
            CommunityScoreWeight.initData()
            // 纬度加载
            CustomDimension.initData()

            // 风险预警参数配置
            RiskWarningConfigure.initData()

            // 评估类型
            if (AssessTypeDict.count() < 1)
            {
                new AssessTypeDict([name: '快速评估', code: '1']).save()
                new AssessTypeDict([name: '人工评估', code: '2']).save()
            }
            // 评估状态
            if (AssessStatusDict.count() < 1)
            {
                new AssessStatusDict([name: '评估成功', code: '1']).save()
                new AssessStatusDict([name: '评估中', code: '2']).save()
                new AssessStatusDict([name: '评估失败', code: '-1']).save()
            }
            // 风险预警处置类型
            if (RiskWarningDealTypeDict.count() < 1)
            {
                new RiskWarningDealTypeDict([name: '押品价值波动', code: 'PriceFluctuations']).save()
            }
            else
            {
                if (!RiskWarningDealTypeDict.findByName('命中反欺诈'))
                {
                    new RiskWarningDealTypeDict([name: '命中反欺诈', code: 'IsAntiFraud']).save()
                }
            }

            if (RiskWarningTypeDict.count() < 1)
            {
                new RiskWarningTypeDict([name: '押品价值波动预警', code: '1']).save()
                new RiskWarningTypeDict([name: '贷款命中反欺诈预警', code: '2']).save()
                new RiskWarningTypeDict([name: '借款人风控预警', code: '3']).save()
                new RiskWarningTypeDict([name: '个人信用等级预警', code: '4']).save()
                new RiskWarningTypeDict([name: '公司信用等级预警', code: '5']).save()
                new RiskWarningTypeDict([name: '舆情预警', code: '6']).save()
                new RiskWarningTypeDict([name: '集中度预警', code: '7']).save()
                new RiskWarningTypeDict([name: '个人逾期/违约', code: '8']).save()
                new RiskWarningTypeDict([name: '公司逾期/违约', code: '9']).save()
                new RiskWarningTypeDict([name: '押品覆盖率预警', code: '10']).save()
                new RiskWarningTypeDict([name: '人员关系预警', code: '11']).save()
                new RiskWarningTypeDict([name: '手机号停用预警', code: '12']).save()
                new RiskWarningTypeDict([name: '工作地点频繁预警', code: '13']).save()
                new RiskWarningTypeDict([name: '押品效期到期监测', code: '14']).save()
                new RiskWarningTypeDict([name: '楼盘风险预警', code: '15']).save()
            }

            if (RiskWarningDisposalMethod.count() < 1)
            {
                new RiskWarningDisposalMethod([name: '立即诉讼', code: '1']).save()
                new RiskWarningDisposalMethod([name: '暂缓诉讼', code: '2']).save()
                new RiskWarningDisposalMethod([name: '催收', code: '3']).save()
            }

            // 权利种类
            if (LoanRightsTypeDict.count() < 1)
            {
                new LoanRightsTypeDict([name: '最高额抵押', code: 'Maximum']).save()
                new LoanRightsTypeDict([name: '一般抵押', code: 'General']).save()
                new LoanRightsTypeDict([name: '抵押', code: 'Normal']).save()
                new LoanRightsTypeDict([name: '典权', code: 'Vadiummortuum']).save()
            }
            // 贷款性质
            if (LoanPropertiesDict.count() < 1)
            {
                new LoanPropertiesDict([name: '组合贷款', code: 'SyndicatedLoan']).save()
                new LoanPropertiesDict([name: '住房公积金贷款', code: 'ProvidentLoan']).save()
                new LoanPropertiesDict([name: '商业贷款', code: 'BusinessLoan']).save()
            }
            // 房屋性质
            if (HouseNatureDict.count() < 1)
            {
                new HouseNatureDict([name: "新房", code: "FistHouse"]).save()
                new HouseNatureDict([name: "二手房", code: "SecondHouse"]).save()
            }
            if (MortgageStatusDict.count() < 1)
            {
                new MortgageStatusDict([name: "未结清", code: "1"]).save()
                new MortgageStatusDict([name: "结清", code: "2"]).save()
                new MortgageStatusDict([name: "逾期", code: "3"]).save()
                new MortgageStatusDict([name: "违约", code: "4"]).save()
            }
            if (AccountTypeDict.count() < 1)
            {
                new AccountTypeDict([name: '担保机构', code: 'GuarantorAccount']).save()
                new AccountTypeDict([name: '评估机构', code: 'EvaluateAccount']).save()
            }
            else
            {
                if (!AccountTypeDict.findByName("贷款机构"))
                {
                    new AccountTypeDict([name: '贷款机构', code: 'MortgageAccount']).save()
                }
                if (!AccountTypeDict.findByName("银行机构"))
                {
                    new AccountTypeDict([name: '银行机构', code: 'BankAccount']).save()
                }
                if (!AccountTypeDict.findByName("委外机构"))
                {
                    new AccountTypeDict([name: '委外机构', code: 'AgencyAccount']).save()
                }
                if (!AccountTypeDict.findByName("资管机构"))
                {
                    new AccountTypeDict([name: '资管机构', code: 'ManagementAccount']).save()
                }
                if (!AccountTypeDict.findByName("律所机构"))
                {
                    new AccountTypeDict([name: '律所机构', code: 'LawAccount']).save()
                }
                if (!AccountTypeDict.findByName("拍卖机构"))
                {
                    new AccountTypeDict([name: '拍卖机构', code: 'AuctioneerAccount']).save()
                }
            }
            if (!AccountTypeDict.findByName("房地产开发商"))
            {
                new AccountTypeDict([name: '房地产开发商', code: 'DeveloperAccount']).save()
            }
            if (RiskWarningStatusDict.count() < 1)
            {
                new RiskWarningStatusDict([name: '未发布', code: '1']).save()
                new RiskWarningStatusDict([name: '已发布', code: '2']).save()
                new RiskWarningStatusDict([name: '已处置', code: '3']).save()
            }
            if (ContactIdentityType.count() < 1)
            {
                new ContactIdentityType([name: '身份证', code: '1']).save()
                new ContactIdentityType([name: '临时身份证', code: '2']).save()
                new ContactIdentityType([name: '护照', code: '3']).save()
            }
            if (MortgagePattern.count() < 1)
            {
                new MortgagePattern([name: '抵押', code: 'mortgage']).save()
                new MortgagePattern([name: '质押', code: 'pledge']).save()
            }
            if (MortgageType.count() < 1)
            {
                new MortgageType([name: '一抵', code: '1']).save()
                new MortgageType([name: '二抵', code: '2']).save()
                new MortgageType([name: '一抵转单', code: '3']).save()
                new MortgageType([name: '二抵转单', code: '4']).save()
            }
            if (MortgageCategory.count() < 1)
            {
                new MortgageCategory([name: '零售贷', code: '1']).save()
                new MortgageCategory([name: '企业贷', code: '2']).save()
                new MortgageCategory([name: '小微贷', code: '3']).save()
            }
            if (VehicleTypeDict.count() < 1)
            {
                new VehicleTypeDict([name: '车辆', code: '1']).save()
                new VehicleTypeDict([name: '船舶', code: '2']).save()
                new VehicleTypeDict([name: '飞行设备', code: '3']).save()
                new VehicleTypeDict([name: '正在建造的船舶、航空器', code: '4']).save()
            }
            if (CurrencyDict.count() < 1)
            {
                new CurrencyDict([name: '人民币', code: '1']).save()
                new CurrencyDict([name: '英镑', code: '2']).save()
                new CurrencyDict([name: '美元', code: '3']).save()
                new CurrencyDict([name: '日元', code: '4']).save()
            }
            if (Cashability.count() < 1)
            {
                new Cashability([name: '强', code: '1']).save()
                new Cashability([name: '适中', code: '2']).save()
                new Cashability([name: '弱', code: '3']).save()
            }
            if (FinancialPledgeTypeDict.count() < 1)
            {
                new FinancialPledgeTypeDict([name: '定期存单', code: '1']).save()
                new FinancialPledgeTypeDict([name: '国债', code: '2']).save()
                new FinancialPledgeTypeDict([name: '票据', code: '3']).save()
                new FinancialPledgeTypeDict([name: '债券', code: '4']).save()
                new FinancialPledgeTypeDict([name: '理财产品', code: '5']).save()
                new FinancialPledgeTypeDict([name: '股票股权', code: '6']).save()
                new FinancialPledgeTypeDict([name: '贵金属', code: '7']).save()
                new FinancialPledgeTypeDict([name: '保单', code: '8']).save()
            }
            if (AccountsReceivableTypeDict.count() < 1)
            {
                new AccountsReceivableTypeDict([name: '交易类应收账款', code: '1']).save()
                new AccountsReceivableTypeDict([name: '道路收费权', code: '2']).save()
                new AccountsReceivableTypeDict([name: '出口退税专用账户', code: '3']).save()
                new AccountsReceivableTypeDict([name: '其他类应收账款', code: '4']).save()
            }
            if (OtherCollateralTypeDict.count() < 1)
            {
                new OtherCollateralTypeDict([name: '仓单', code: '1']).save()
                new OtherCollateralTypeDict([name: '提单', code: '2']).save()
                new OtherCollateralTypeDict([name: '存货', code: '3']).save()
                new OtherCollateralTypeDict([name: '其他动产质押物', code: '4']).save()
                new OtherCollateralTypeDict([name: '经营权', code: '5']).save()
                new OtherCollateralTypeDict([name: '其他权利质押物', code: '6']).save()
                new OtherCollateralTypeDict([name: '知识产权', code: '7']).save()
            }
            if (ManagementRightsType.count() < 1)
            {
                new ManagementRightsType([name: '注册商标专用权', code: '1']).save()
                new ManagementRightsType([name: '专利权', code: '2']).save()
                new ManagementRightsType([name: '著作权', code: '3']).save()
            }
            if (ContactType.count() < 1)
            {
                new ContactType([name: '借款人', code: '1']).save()
                new ContactType([name: '借款人配偶', code: '2']).save()
                new ContactType([name: '抵押人', code: '3']).save()
                new ContactType([name: '抵押人配偶', code: '4']).save()
                new ContactType([name: '其它借款人', code: '5']).save()
                new ContactType([name: '借款人父母', code: '6']).save()
                new ContactType([name: '借款人子女', code: '7']).save()
            }
            if (CollateralType.count() < 1)
            {
                new CollateralType([name: '房地产', code: 'estate']).save()
                new CollateralType([name: '交通运输工具', code: 'vehicle']).save()
                new CollateralType([name: '金融质押品', code: 'financialPledge']).save()
                new CollateralType([name: '应收账款', code: 'accountsReceivable']).save()
                new CollateralType([name: '其他抵质押品', code: 'otherCollateral']).save()
            }
            if (ContractType.count() < 1)
            {
                new ContractType([name: '借款合同', code: '1']).save()
                new ContractType([name: '抵押合同', code: '2']).save()
                new ContractType([name: '质押合同', code: '3']).save()
                new ContractType([name: '保证合同', code: '4']).save()
            }

            if (WorkflowType.count() < 1)
            {
                new WorkflowType([name: '押品', code: '01']).save()
                new WorkflowType([name: '贷款', code: '02']).save()
                new WorkflowType([name: '借款人', code: '03']).save()
                new WorkflowType([name: '预警', code: '04']).save()
                new WorkflowType([name: '不良资产包', code: '05']).save()
                new WorkflowType([name: '机构', code: '06']).save()
            }

            if (CollateralStage.count() < 1)
            {
                def type = WorkflowType.findByName("押品")

                new CollateralStage([name: '预登记', code: '01', type: type]).save()
                new CollateralStage([name: '预登记已提交', code: '05', type: type]).save()
                new CollateralStage([name: '已正式登记', code: '11', type: type]).save()
                new CollateralStage([name: '押品已入库', code: '21', type: type]).save()

                new CollateralStage([name: '申请结清出库', code: '30', type: type]).save()
                new CollateralStage([name: '已申请结清出库', code: '31', type: type]).save()
                new CollateralStage([name: '已确认结清出库', code: '33', type: type]).save()
                new CollateralStage([name: '已结清出库', code: '35', type: type]).save()

                new CollateralStage([name: '申请强制出库', code: '40', type: type]).save()
                new CollateralStage([name: '已申请强制出库', code: '41', type: type]).save()
                new CollateralStage([name: '已确认强制出库', code: '43', type: type]).save()
                new CollateralStage([name: '已强制出库', code: '45', type: type]).save()

                new CollateralStage([name: '申请借出', code: '50', type: type]).save()
                new CollateralStage([name: '已申请借出', code: '51', type: type]).save()
                new CollateralStage([name: '已确认借出', code: '53', type: type]).save()
                new CollateralStage([name: '已借出', code: '55', type: type]).save()

                new CollateralStage([name: '申请归还', code: '60', type: type]).save()
                new CollateralStage([name: '已申请归还', code: '61', type: type]).save()
                new CollateralStage([name: '已确认归还', code: '65', type: type]).save()
                new CollateralStage([name: '已归还再入库', code: '80', type: type]).save()

                new CollateralStage([name: '申请置换出库', code: '100', type: type]).save()
                new CollateralStage([name: '已申请置换出库', code: '101', type: type]).save()
                new CollateralStage([name: '已确认置换出库', code: '103', type: type]).save()
                new CollateralStage([name: '已置换出库', code: '105', type: type]).save()
            }

            if (RiskWarningStage.count() < 1)
            {
                def type = WorkflowType.findByName("预警")
                new RiskWarningStage([name: '已发布', code: '01', type: type]).save()
                new RiskWarningStage([name: '申请催收', code: '02', type: type]).save()
                new RiskWarningStage([name: '申请诉讼', code: '03', type: type]).save()
                new RiskWarningStage([name: '已申请催收', code: '05', type: type]).save()
                new RiskWarningStage([name: '经理已审批催收', code: '08', type: type]).save()
                new RiskWarningStage([name: '行长已审批催收', code: '10', type: type]).save()
                new RiskWarningStage([name: '已处置分发', code: '13', type: type]).save()
                new RiskWarningStage([name: '已处置安排', code: '16', type: type]).save()
                new RiskWarningStage([name: '已催收', code: '18', type: type]).save()
                new RiskWarningStage([name: '已申请诉讼', code: '20', type: type]).save()
                new RiskWarningStage([name: '经理已审批诉讼', code: '23', type: type]).save()
                new RiskWarningStage([name: '行长已审批诉讼', code: '25', type: type]).save()
                new RiskWarningStage([name: '已代偿', code: '28', type: type]).save()
                new RiskWarningStage([name: '已立案', code: '30', type: type]).save()
                new RiskWarningStage([name: '已开庭', code: '32', type: type]).save()
                new RiskWarningStage([name: '已判决', code: '35', type: type]).save()
                new RiskWarningStage([name: '已二审上诉', code: '37', type: type]).save()
                new RiskWarningStage([name: '已二审开庭', code: '40', type: type]).save()
                new RiskWarningStage([name: '已二审判决', code: '42', type: type]).save()
                new RiskWarningStage([name: '已申请执行', code: '44', type: type]).save()
                new RiskWarningStage([name: '已拍卖', code: '47', type: type]).save()
                new RiskWarningStage([name: '已结束', code: '50', type: type]).save()
                new RiskWarningStage([name: '已处置', code: '80', type: type]).save()
                new RiskWarningStage([name: '申请暂缓诉讼', code: '89', type: type]).save()
                new RiskWarningStage([name: '已申请暂缓诉讼', code: '90', type: type]).save()
                new RiskWarningStage([name: '经理已审批暂缓诉讼', code: '92', type: type]).save()
                new RiskWarningStage([name: '行长已审批暂缓诉讼', code: '94', type: type]).save()
                new RiskWarningStage([name: '还款日期已确认', code: '96', type: type]).save()
                new RiskWarningStage([name: '信息已完善', code: '98', type: type]).save()
                new RiskWarningStage([name: '已完成资产核查', code: '100', type: type]).save()
                new RiskWarningStage([name: '已转让', code: '102', type: type]).save()
            }

            if (AbnormalMortgageBatchStage.count() < 1)
            {
                def type = WorkflowType.findByName("不良资产包")
                new AbnormalMortgageBatchStage([name: '已发布', code: '01', type: type]).save()
                new AbnormalMortgageBatchStage([name: '申请不良资产打包', code: '02', type: type]).save()
                new AbnormalMortgageBatchStage([name: '不良资产已打包', code: '03', type: type]).save()
                new AbnormalMortgageBatchStage([name: '经理已审批不良资产打包', code: '04', type: type]).save()
                new AbnormalMortgageBatchStage([name: '行长已审批不良资产打包', code: '05', type: type]).save()
                //                new AbnormalMortgageBatchStage([name: '申请催收', code: '02', type: type]).save()
                //                new AbnormalMortgageBatchStage([name: '申请诉讼', code: '03', type: type]).save()
                //                new AbnormalMortgageBatchStage([name: '已申请催收', code: '05', type: type]).save()
                //                new AbnormalMortgageBatchStage([name: '经理已审批催收', code: '08', type: type]).save()
                //                new AbnormalMortgageBatchStage([name: '行长已审批催收', code: '10', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已处置分发', code: '13', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已处置安排', code: '16', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已催收', code: '18', type: type]).save()
                //                new AbnormalMortgageBatchStage([name: '已申请诉讼', code: '20', type: type]).save()
                //                new AbnormalMortgageBatchStage([name: '经理已审批诉讼', code: '23', type: type]).save()
                new AbnormalMortgageBatchStage([name: '待诉讼', code: '25', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已代偿', code: '28', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已立案', code: '30', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已开庭', code: '32', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已判决', code: '35', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已二审上诉', code: '37', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已二审开庭', code: '40', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已二审判决', code: '42', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已申请执行', code: '44', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已拍卖', code: '47', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已结束', code: '50', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已处置', code: '80', type: type]).save()
                new AbnormalMortgageBatchStage([name: '申请暂缓诉讼', code: '89', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已申请暂缓诉讼', code: '90', type: type]).save()
                //                new AbnormalMortgageBatchStage([name: '经理已审批暂缓诉讼', code: '92', type: type]).save()
                //                new AbnormalMortgageBatchStage([name: '行长已审批暂缓诉讼', code: '94', type: type]).save()
                new AbnormalMortgageBatchStage([name: '还款日期已确认', code: '96', type: type]).save()
                new AbnormalMortgageBatchStage([name: '信息已完善', code: '98', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已完成资产核查', code: '100', type: type]).save()
                new AbnormalMortgageBatchStage([name: '已转让', code: '102', type: type]).save()
            }

            if (AccountStage.count() < 1)
            {
                def type = WorkflowType.findByName("机构")

                new AccountStage([name: '申请创建机构', code: '01', type: type]).save()
                new AccountStage([name: '已申请创建机构', code: '05', type: type]).save()
                new AccountStage([name: '经理已审批创建机构', code: '11', type: type]).save()
                new AccountStage([name: '行长已审批创建机构', code: '21', type: type]).save()
            }

            if (TeamRole.count() < 1)
            {
                new TeamRole([name: '只读', code: 'Read']).save()
                new TeamRole([name: '可写', code: 'Edit']).save()
                new TeamRole([name: '管理员', code: 'Administrator']).save()
                new TeamRole([name: '批准', code: 'Approval']).save()
            }
            if (WarrantType.count() < 1)
            {
                new WarrantType([name: '他证', code: '1']).save()
                new WarrantType([name: '产证', code: '2']).save()
                new WarrantType([name: '仓单', code: '3']).save()
                new WarrantType([name: '提单', code: '4']).save()
                new WarrantType([name: '汽车合格证', code: '5']).save()
                new WarrantType([name: '其他', code: '6']).save()
            }
            if (AttachmentType.count() < 1)
            {
                new AttachmentType([name: '户口本', code: '01']).save()
                new AttachmentType([name: '房产证', code: '02']).save()
                new AttachmentType([name: '购房合同', code: '03']).save()
                new AttachmentType([name: '婚姻证明', code: '04']).save()
                new AttachmentType([name: '借款人身份证', code: '05']).save()
                new AttachmentType([name: '借款人配偶身份证', code: '06']).save()
                new AttachmentType([name: '抵押人身份证', code: '07']).save()
                new AttachmentType([name: '抵押人配偶身份证', code: '08']).save()
                new AttachmentType([name: '小区外围配套物业', code: '09']).save()
                new AttachmentType([name: '出入口道路', code: '10']).save()
                new AttachmentType([name: '小区名称及物业地址', code: '11']).save()
                new AttachmentType([name: '小区楼栋号、单元号、门牌号', code: '12']).save()
                new AttachmentType([name: '小区规模', code: '13']).save()
                new AttachmentType([name: '抵押物各房间情况', code: '14']).save()
                new AttachmentType([name: '估值附回材料', code: '15']).save()
                new AttachmentType([name: '产调结果', code: '16']).save()
                new AttachmentType([name: '他项证明', code: '17']).save()
                new AttachmentType([name: '放款证明', code: '18']).save()
                new AttachmentType([name: '签约合同', code: '19']).save()
                new AttachmentType([name: '被执情况', code: '20']).save()
                new AttachmentType([name: '公证书', code: '21']).save()
                new AttachmentType([name: '担保合同', code: '22']).save()
                new AttachmentType([name: '协议信息', code: '23']).save()
                new AttachmentType([name: '业务合同', code: '24']).save()
                new AttachmentType([name: '贷款合同', code: '25']).save()
                new AttachmentType([name: '抵押合同', code: '26']).save()
                new AttachmentType([name: '放款信息', code: '27']).save()
                new AttachmentType([name: '保险合同', code: '28']).save()
                new AttachmentType([name: '共有财产权证明', code: '29']).save()
                new AttachmentType([name: '收入证明', code: '30']).save()
                new AttachmentType([name: '家庭其他财产证明', code: '31']).save()
                new AttachmentType([name: '营业执照正本及副本', code: '32']).save()
                new AttachmentType([name: '组织机构代码证书正本', code: '33']).save()
                new AttachmentType([name: '税务登记证', code: '34']).save()
                new AttachmentType([name: '基本户开户许可证', code: '35']).save()
                new AttachmentType([name: '公司其他股东身份证', code: '36']).save()
                new AttachmentType([name: '企业银行对帐单', code: '37']).save()
                new AttachmentType([name: '上年度财务报表', code: '38']).save()
                new AttachmentType([name: '近三个月财务报表', code: '39']).save()
                new AttachmentType([name: '公司情况介绍及用款说明', code: '40']).save()
            }


            if (BorrowerTypeDict.count() < 1)
            {
                new BorrowerTypeDict([name: '企业', code: '01']).save()
                new BorrowerTypeDict([name: '个人', code: '02']).save()

            }

            if (LoansUseDict.count() < 1)
            {
                new LoansUseDict([name: '资金周转', code: '01']).save()
                new LoansUseDict([name: '购房', code: '02']).save()
                new LoansUseDict([name: '购车', code: '03']).save()
                new LoansUseDict([name: '经营', code: '04']).save()

            }

            if (PayInterestTypeDict.count() < 1)
            {
                new PayInterestTypeDict([name: '定期结息', code: '01']).save()
                new PayInterestTypeDict([name: '等额本息', code: '02']).save()
                new PayInterestTypeDict([name: '等额本金', code: '03']).save()

            }
            if (ComponentType.count() < 1)
            {
                new ComponentType([name: '条件', code: 'Condition']).save()
                new ComponentType([name: '事件', code: 'Event']).save()
                new ComponentType([name: '系统', code: 'Systerm']).save()
            }
            if (CreditScoreRiskDimension.count() < 1)
            {
                new CreditScoreRiskDimension([label: '高风险', minValue: '0', maxValue: '30', orderNumber: 1]).save()
                new CreditScoreRiskDimension([label: '高中风险', minValue: '30', maxValue: '50', orderNumber: 2]).save()
                new CreditScoreRiskDimension([label: '中风险', minValue: '50', maxValue: '70', orderNumber: 3]).save()
                new CreditScoreRiskDimension([label: '低风险', minValue: '70', maxValue: '200', orderNumber: 4]).save()
            }
            if (ContactRiskWarningDispositionType.count() < 1)
            {
                new ContactRiskWarningDispositionType([name: '起诉', code: '1']).save()
                new ContactRiskWarningDispositionType([name: '上门催收', code: '2']).save()
                new ContactRiskWarningDispositionType([name: '电话催收', code: '3']).save()
            }
            if (MortgageCollectionType.count() < 1)
            {
                new MortgageCollectionType([name: '电话催收', code: '1']).save()
                new MortgageCollectionType([name: '短信催收', code: '2']).save()
                new MortgageCollectionType([name: '邮件催收', code: '3']).save()
                new MortgageCollectionType([name: '上门催收', code: '4']).save()
            }
            if (RiskWarningConfig.count() < 1)
            {
                new RiskWarningConfig([label: '价值上升波动范围', code: '1', minValue: 0.1, minOperator: '大于等于', orderNumber: 1]).save()
                new RiskWarningConfig([label: '价值下降波动范围', code: '2', minValue: -0.1, minOperator: '小于等于', orderNumber: 5]).save()
                new RiskWarningConfig([label: '个人逾期次数', code: '3', minValue: 6, minOperator: '大于等于', orderNumber: 10]).save()
                new RiskWarningConfig([label: '个人违约次数', code: '4', minValue: 2, minOperator: '大于等于', orderNumber: 15]).save()
                new RiskWarningConfig([label: '企业逾期次数', code: '5', minValue: 6, minOperator: '大于等于', orderNumber: 20]).save()
                new RiskWarningConfig([label: '企业违约次数', code: '6', minValue: 2, minOperator: '大于等于', orderNumber: 25]).save()
                new RiskWarningConfig([label: '集中度风险综合评分', code: '7', minValue: 3, minOperator: '大于等于', orderNumber: 30]).save()
                new RiskWarningConfig([label: '城市占比覆盖率', code: '8', minValue: 0.1, minOperator: '大于等于', orderNumber: 35]).save()
                new RiskWarningConfig([label: '小区占比覆盖率', code: '9', minValue: 0.1, minOperator: '大于等于', orderNumber: 40]).save()
                new RiskWarningConfig([label: '到期距离天数', code: '10', minValue: 30, minOperator: '大于等于', orderNumber: 45]).save()
                new RiskWarningConfig([label: '楼盘评分', code: '11', minValue: 3, minOperator: '大于等于', orderNumber: 50]).save()
                new RiskWarningConfig([label: '抵质押物', code: '12', orderNumber: 55]).save()
                new RiskWarningConfig([label: '借款人（企业/个人）', code: '13', orderNumber: 60]).save()
                new RiskWarningConfig([label: '关注类贷款', code: '14', orderNumber: 65]).save()
                new RiskWarningConfig([label: '次级类贷款', code: '15', orderNumber: 70]).save()
                new RiskWarningConfig([label: '可疑类贷款', code: '16', orderNumber: 75]).save()
                new RiskWarningConfig([label: '损失类贷款', code: '17', orderNumber: 80]).save()
                new RiskWarningConfig([label: '多头借贷', code: '18', orderNumber: 85]).save()
                new RiskWarningConfig([label: '出行信息', code: '19', orderNumber: 90]).save()
                new RiskWarningConfig([label: '运营商信息', code: '20', orderNumber: 95]).save()
                new RiskWarningConfig([label: '司法信息', code: '21', orderNumber: 100]).save()
                new RiskWarningConfig([label: '行政信息', code: '22', orderNumber: 105]).save()
                new RiskWarningConfig([label: '行政信息', code: '23', orderNumber: 110]).save()

            }
        }

    def destroy = {}
}